﻿<ClientManagerView:EventResourceDictionary x:Class="FacebookClient.GalleryHomeEventResourceDictionary"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ClientManager="clr-namespace:ClientManager"
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:ClientManagerView="clr-namespace:ClientManager.View"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    xmlns:FacebookClient="clr-namespace:FacebookClient">
  
  <FacebookClient:AddConverter x:Key="AddConverter" />
  <FacebookClient:DateTimeToStringConverter x:Key="DateTimeConverter"/>
  
  <!-- Item outline brush -->
  <SolidColorBrush x:Key="Border_ItemOutline" Color="#444444" />

  <!-- Item outline brush thickness -->
  <Thickness x:Key="Border_ItemOutline_Thickness">1</Thickness>

  <!-- Default brush for content hightlights -->
  <SolidColorBrush x:Key="Foreground_ContentHighlight" Color="#0099ff"/>

  <!-- Template to display one photo and the album title, used on the homepage list view -->
  <DataTemplate x:Key="ListPhotoAlbumPreview">
    <FacebookClient:AlbumThumbnailButton
        FacebookPhotoAlbum="{Binding}"
        Click="OnNavigateToContentButtonClicked" 
        ClientManagerView:ViewManager.NavigationContent="{Binding}">
      <FacebookClient:AlbumThumbnailButton.Style>
        <Style TargetType="{x:Type FacebookClient:AlbumThumbnailButton}">
          <Setter Property="Cursor" Value="Hand"/>
          <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
          <Setter Property="Panel.ZIndex" Value="1"/>
          <Setter Property="Template" Value="{DynamicResource AlbumThumbnailTemplate}"/>
          <Setter Property="ShowOwnerOverlay" Value="True" />
          <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FacebookClient:GalleryHomeControl}}, Path=ShowOwnerOverlay}" Value="False">
              <Setter Property="ShowOwnerOverlay" Value="False" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </FacebookClient:AlbumThumbnailButton.Style>-->
    </FacebookClient:AlbumThumbnailButton>
  </DataTemplate>
  
  <ControlTemplate x:Key="GalleryHome_Normal" TargetType="{x:Type FacebookClient:GalleryHomeControl}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <FacebookClient:SortControl DockPanel.Dock="Left" Width="200" SortOrderMode="Albums" TitleText="{Binding Path=Count, StringFormat=\{0\} albums}">
        <FacebookClient:SortControl.Style>
          <Style TargetType="{x:Type FacebookClient:SortControl}">
            <Setter Property="Visibility" Value="Visible" />
            <Style.Triggers>
              <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FacebookClient:GalleryHomeControl}}, Path=ShowSortBar}" Value="False">
                <Setter Property="Visibility" Value="Collapsed" />
              </DataTrigger>
              <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FacebookClient:MainWindow}}, Path=IsInSmallMode}" Value="True">
                <Setter Property="Visibility" Value="Collapsed" />
              </DataTrigger>
            </Style.Triggers>
          </Style>
        </FacebookClient:SortControl.Style>
      </FacebookClient:SortControl>

      <FacebookClient:PaginatedItemsControl 
          x:Name="GalleryPreviewListBox"
          Grid.Column="1"
          Margin="20,20,5,10"
          Background="Transparent"
          BorderBrush="Transparent"
          ItemTemplate="{StaticResource ListPhotoAlbumPreview}"
          KeyboardNavigation.DirectionalNavigation="Contained"
          KeyboardNavigation.TabNavigation="Contained"
          PaginatedItemsSource="{Binding}"
          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
          ScrollViewer.VerticalScrollBarVisibility="Disabled">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <FacebookClient:AnimatingTilePanel Attraction="2.4" ItemHeight="170" ItemWidth="220" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </FacebookClient:PaginatedItemsControl>

      <Grid Grid.Column="1" 
            HorizontalAlignment="Right" 
            VerticalAlignment="Bottom" 
            Margin="0,0,0,5" 
            DataContext="{Binding ElementName=GalleryPreviewListBox, Path=ListPager}">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <RepeatButton
            Style="{DynamicResource SimpleButtonBaseStyle}"
            Grid.Column="0"
            Margin="5,1"
            Command="{Binding Path=PreviousCommand}" 
            ToolTip="Previous page">
          <Rectangle Height="25" Width="25" Fill="{DynamicResource LeftArrowToolbarDrawingBrush}"/>
        </RepeatButton>
        <TextBlock Grid.Column="1" Style="{DynamicResource ToolbarTextBlockStyle}" TextAlignment="Center" MinWidth="80">
          <TextBlock.Text>
            <MultiBinding StringFormat="{}Page {0} of {1}">
              <Binding Path="CurrentPageIndex" Converter="{StaticResource AddConverter}" ConverterParameter="1" />
              <Binding Path="PageCount" />
            </MultiBinding>
          </TextBlock.Text>
        </TextBlock>
        <RepeatButton
            Style="{DynamicResource SimpleButtonBaseStyle}"
            Grid.Column="2"
            Margin="5,1"
            Command="{Binding Path=NextCommand}" 
            ToolTip="Next page">
          <Rectangle Height="25" Width="25" Fill="{DynamicResource RightArrowToolbarDrawingBrush}"/>
        </RepeatButton>
      </Grid>
    </Grid>
  </ControlTemplate>
  
  <!-- Collection of templates to use for the gallery home control, depending on the amount of space available -->
  <ClientManagerControls:SizeControlTemplateCollection x:Key="GalleryHomeTemplateCollection">
    <ClientManagerControls:SizeControlTemplate MinHeight="0" MinWidth="0" Template="{StaticResource GalleryHome_Normal}"/>
  </ClientManagerControls:SizeControlTemplateCollection>
  
  <!-- Summary view of multiple albums. -->
  <DataTemplate DataType="{x:Type Facebook:FacebookPhotoAlbumCollection}">
    <FacebookClient:GalleryHomeControl x:Name="GalleryHomeControl" FocusVisualStyle="{x:Null}" Templates="{DynamicResource GalleryHomeTemplateCollection}"/>
  </DataTemplate>
  
</ClientManagerView:EventResourceDictionary>